package com.qdlc.p2p.manage.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.UserVipLevelService;
import com.qdlc.p2p.biz.service.UserVipService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dto.UserVip;
import com.qdlc.p2p.dal.dto.UserVipLevel;
import com.qdlc.p2p.dal.model.UserVipGrowthLogModel;
import com.qdlc.p2p.dal.model.UserVipModel;

/**
 * vip管理
 * 
 * @author zf
 * @version 2.0
 */
public class ManageUserVipAction extends BaseAction<UserVipModel> implements ModelDriven<UserVipModel> {

	@Resource
	private UserVipService userVipService;
	@Resource
	private UserVipLevelService vipLevelService;

	private Map<String, Object> data = new HashMap<String, Object>();

	/**
	 * vip管理
	 * @return
	 * @throws Exception
	 */
	@Action(value = "/modules/user/vip/vipManager")
	public String vipManager() throws Exception {
		List<UserVipLevel> list = vipLevelService.getAllLevel();
		request.setAttribute("list", list);
		return "vipManager";
	}

	/**
	 * vip列表
	 * @return
	 * @throws Exception
	 */
	@Action(value = "/modules/user/vip/vipList")
	public void vipList() throws Exception {
		if(request.getParameter("vipLevel") == null) {
			model.setVipLevel(-1);
		}
		PageDataList<UserVipModel> pagaDataList = userVipService.getVipList(model);
		int totalPage = pagaDataList.getPage().getTotal();// 总页数
		data.put("total", totalPage);
		data.put("rows", pagaDataList.getList());
		printJson(getStringOfJpaObj(data));
	}
	/**
	 * 跳转用户vip成长值列表
	 * @return
	 * @throws Exception
	 */
	@Action("/modules/user/vip/vipGrowthLogDetailPage")
	public String vipGrowthLogDetailPage() throws Exception {
		UserVip userVip = userVipService.getUserVipById(model.getId());
		request.setAttribute("userId", userVip.getUserId());
		return "vipGrowthLogDetailPage";
	}
	/**
	 * vip成长值列表
	 * @throws IOException
	 */
	@Action("/modules/user/vip/vipGrowthLogList")
	public void vipGrowthLogList() throws IOException{
		long userId = paramLong("userId");
		PageDataList<UserVipGrowthLogModel> pageDataList = userVipService
				.getUserVipGrowthLogListByUserId(userId,  model.getPage(), paramInt("rows"));
		data.put("total", pageDataList.getPage().getTotal());
		data.put("rows", pageDataList.getList());
		printJson(getStringOfJpaObj(data));
	}
	
}
